package com.shizhanzhe.zxbapp.team;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.shizhanzhe.zxbapp.R;
import com.shizhanzhe.zxbapp.bean.TeamMoney;
import com.shizhanzhe.zxbapp.url.Path;
import com.shizhanzhe.zxbapp.utils.Util;

import java.util.List;


/**
 * Created by zz9527 on 2018/11/28.
 */
public class TeamAdapter extends BaseAdapter {
    private final LayoutInflater inflater;
    private List<TeamMoney.DataBean.TeamsBean> list;
    private Context context;
    private int type;
    public TeamAdapter(Context context, List<TeamMoney.DataBean.TeamsBean> list,int type) {
        this.context=context;
        this.list=list;
        this.type=type;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHold hold;
        if (type!=7) {
            if (view == null) {
                view = inflater.inflate(R.layout.adapter_team, null);
                hold = new ViewHold();
                hold.iv = view.findViewById(R.id.team_iv);
                hold.name = view.findViewById(R.id.team_name);
                hold.price = view.findViewById(R.id.team_money);
                view.setTag(hold);
            } else {
                hold = (ViewHold) view.getTag();
            }
            TeamMoney.DataBean.TeamsBean bean = list.get(i);
            Glide.with(context).load(Path.img(bean.getAvatar())).apply(new RequestOptions().error(R.mipmap.logo)).into(hold.iv);
            hold.name.setText(bean.getNickname());
            switch (type) {
                case 1:
                    hold.price.setText(bean.getDaybalance() + "元");
                    break;
                case 2:
                    hold.price.setText(bean.getMonthbalance() + "元");
                    break;
                case 3:
                    hold.price.setText(bean.getTotalbalance() + "元");
                    break;
                case 4:
                case 5:
                case 6:
                    hold.price.setText(Util.getDateTimeFromMillisecond(bean.getViptime()));
                    break;
                case 8:
                    hold.price.setText(bean.getTotalbalance() + "元");
                    break;
            }
        }else {
            if (view == null) {
                view = inflater.inflate(R.layout.item_team, null);
                hold = new ViewHold();
                hold.iv = view.findViewById(R.id.team_iv);
                hold.name = view.findViewById(R.id.team_name);
                view.setTag(hold);
            } else {
                hold = (ViewHold) view.getTag();
            }
            TeamMoney.DataBean.TeamsBean bean = list.get(i);
            Glide.with(context).load(Path.img(bean.getAvatar())).into(hold.iv);
            hold.name.setText(bean.getNickname());
        }
        return view;
    }
    class ViewHold{
        ImageView iv;
        TextView name;
        TextView price;
    }

}
